/**
 * 添加或者更新WTChangeOrder2对象到中间表
 */
package ext.generic.integration.oa.service;

import java.util.Enumeration;

import wt.change2.WTChangeOrder2;
import wt.fc.WTObject;

import com.infoengine.object.IeObject;
import com.infoengine.object.factory.Group;

import ext.generic.integration.oa.task.ECNIETask;

public class CreateOrUpdateECNService {
	
	public static void createOrUpdateMethod( WTObject  wtObject ){
		
		if( wtObject != null && wtObject instanceof WTChangeOrder2){
			WTChangeOrder2 ecn = ( WTChangeOrder2 )wtObject;
			
			ECNIETask.add( ecn );
		}		
	}
	
	/**
	 * 查看OA是否接收成功
	 * @param wtObject
	 * @return
	 */
	public static String gainReleaseState( WTObject wtObject ){
		
		if( wtObject == null ){
			return "";
		}
		
		WTChangeOrder2 ecn = null;
		
		if( wtObject instanceof WTChangeOrder2 ){
			ecn = ( WTChangeOrder2 )wtObject;
		}
		
		Group group = ECNIETask.query( ecn );
		
		
		
		return gainReleaseState( group );
		
	}
	
	private static String gainReleaseState(Group group) {		
		String releaseState = "";
		
		if( group == null ){
			return releaseState;
		}
		
		Enumeration enumeration = group.getGroup().getChildren();
		IeObject ieoRecord = null;
		if( enumeration != null ){
			
			while( enumeration.hasMoreElements() ){
				ieoRecord = (IeObject)enumeration.nextElement();
				
				if( ieoRecord != null ){
					releaseState = ieoRecord.getAtt("flag").getDatum().toString();
				}
			}
		}
		
		return releaseState;
	}
}
